function printc(text)

	messages = {}

	table.insert(messages, text)

	console_text = text

end


function draw_hud()

	local name_x = 2*tile_size+(grid_size*tile_size)
	local name_y = tile_size
	local gender_x = 2*tile_size+(grid_size*tile_size)
	local gender_y = tile_size*2
	local lhand_x = name_x+tile_size*8

	-- name and gender
	love.graphics.print(data.player.name,
		name_x,
		name_y)
	love.graphics.print(data.player.gender,
		gender_x,
		gender_y)

	-- construct health
	local rh = math.floor(data.player.health)
	local mh = data.player.max_health .. ""
	local hs = rh .. ""
	local hs2 = append_strings("\\", mh)
	local hs3 = append_strings(hs, hs2)
	love.graphics.print("h : ",
		gender_x,
		gender_y+tile_size)
	love.graphics.print(hs3,
		gender_x+2*tile_size,
		gender_y+tile_size)

	-- construct stamina

	local ms = data.player.max_stam .. ""
	local ss = data.player.stamina .. ""
	local ss2 = append_strings("\\",ms)
	local ss3 = append_strings(ss,ss2)
	love.graphics.print("s : ",
		gender_x,
		gender_y+2*tile_size)
	love.graphics.print(ss3,
		gender_x+2*tile_size,
		gender_y+2*tile_size)

	-- construct xp

	local mxs = data.player.req_xp .. ""
	local xs = data.player.xp .. ""
	local xs2 = append_strings("\\",mxs)
	local xs3 = append_strings(xs,xs2)
	love.graphics.print("xp : ",
		gender_x,
		gender_y+3*tile_size)
	love.graphics.print(xs3,
		gender_x+2*tile_size,
		gender_y+3*tile_size)

	-- construct current level

	local cl = data.player.current_harvest .. ""
	local cl2 = append_strings(cl, "\\10")
	love.graphics.print("# : ",
		gender_x,
		gender_y+4*tile_size)
	love.graphics.print(cl2,
		gender_x+2*tile_size,
		gender_y+4*tile_size)


	-- console output
	love.graphics.print(console_text,
		tile_size, grid_size*tile_size+tile_size)

	-- left and right hand
	love.graphics.print("r : ", lhand_x,
		name_y)

	if data.player.right_hand[1] ~= nil then
		love.graphics.setFont(small_font)
		love.graphics.print(data.player.right_hand[1].name,
			lhand_x+tile_size,
			name_y+4)
		love.graphics.setFont(norm_font)


	end

	love.graphics.print("l : ", lhand_x,
		gender_y)

	if data.player.left_hand[1] ~= nil then
		love.graphics.setFont(small_font)
		love.graphics.print(data.player.left_hand[1].name,
			lhand_x+tile_size,
			gender_y+4)
		love.graphics.setFont(norm_font)

	end

	-- seeds
	love.graphics.print("seeds : ", lhand_x,
			gender_y+tile_size)

	love.graphics.print(math.floor(data.player.seeds), lhand_x+tile_size*4,
			gender_y+tile_size)

	-- bullets
	love.graphics.print("b : ", lhand_x,
		gender_y+2*tile_size)
	love.graphics.print(data.player.bullets, lhand_x+tile_size*4,
		gender_y+2*tile_size)

	-- console input
	if data.player.text_input == true then
		love.graphics.print(">",
			tile_size-8, grid_size*tile_size+2*tile_size)
		love.graphics.print(data.player.con_text,
			tile_size+8, grid_size*tile_size+2*tile_size)
	end



	-- inventory


	for i = 1, 9 do
		if data.player.inventory[i] ~= nil then
			love.graphics.print(data.player.inventory[i].name,
				grid_size*tile_size+tile_size*4, tile_size*10+(i*tile_size))
			if data.player.inventory[i].desc ~= nil then
				local gf = love.graphics.getFont()
				local nl = gf:getWidth(data.player.inventory[i].name)

				love.graphics.setFont(small_font)
				love.graphics.print(data.player.inventory[i].desc,
				(grid_size*tile_size+tile_size*4)+nl, tile_size*10+(i*tile_size))
				love.graphics.setFont(norm_font)
			end
			love.graphics.print(i,
				grid_size*tile_size+tile_size*2, tile_size*10+(i*tile_size))
		end
	end

	-- quest list

	love.graphics.print("quests : ",
		grid_size*tile_size+tile_size*2,
		grid_size*tile_size)

	if data.player.quests ~= nil then
		for i = 1, #data.player.quests do

			love.graphics.print(data.player.quests[i],
				grid_size*tile_size+tile_size*2,
				grid_size*tile_size+(i*tile_size))

		end

	end

	-- enemy list

	if show_enemy ~= nil then
		for i = 1, #show_enemy do
			--print("in show_enemy : ", i)
			if i < 5 then
					--print("drawing.. ", show_enemy[i].name)
					love.graphics.print(show_enemy[i].name,
						grid_size*tile_size+tile_size*2,
						tile_size*10+(11*tile_size)+(i*tile_size))
					love.graphics.print(show_enemy[i].health,
						grid_size*tile_size+tile_size*8,
						tile_size*10+(11*tile_size)+(i*tile_size))


			end
		end

	end



	if data.fps == true then
		love.graphics.print("Current FPS: "..tostring(love.timer.getFPS( )),
			10, 10)

	end




end

function clear_console()
	console_text = ""
end



function draw_in_fov(entity)
	if entity.explored == false then
		love.graphics.setColor(89,47,50,255)

		love.graphics.rectangle("fill",entity.x, entity.y, tile_size, tile_size)

		love.graphics.setColor(255,255,255,255)


	else
		-- within range
		--print(local_map.name, entity.type)
		if p_fov(entity.x, entity.y) then
			if entity.type == "floor" and data.player.local_map.name == "town" then
				love.graphics.drawq(env_sheet_img, entity.image,
						entity.x,entity.y,0,2.0,2.0)
			elseif entity.type == "wall" and entity.name == "tree" then
				-- standing tree
				love.graphics.draw(brown_grain_img,
					entity.x, entity.y)
				love.graphics.draw(entity.image,
					entity.x, entity.y)
			elseif entity.type == "floor" and entity.name == "tree" then
				-- cut down tree
				love.graphics.draw(brown_grain_img,
				entity.x, entity.y)
				love.graphics.draw(tree_stump_img,
				entity.x, entity.y)

			elseif entity.type == "meta" then

				if entity.image ~= nil then

					love.graphics.draw(entity.image,
						entity.x, entity.y, 0, 16/entity.image:getWidth(),
						16/entity.image:getHeight())

					love.graphics.draw(bgb_outl_img,
						entity.x, entity.y)

				else
					love.graphics.setColor(0,0,0)
					love.graphics.rectangle("fill",entity.x,
						entity.y, tile_size, tile_size)
					love.graphics.setColor(255,255,255)
					love.graphics.draw(bgb_outl_img,
						entity.x, entity.y)

				end

			elseif entity.name == "stairs_up" then
				love.graphics.drawq(env_sheet_img,
						entity.image,
						entity.x,
						entity.y,
						0, 2.0, 2.0)

			elseif entity.name == "stairs_down" then
				love.graphics.drawq(env_sheet_img,
						entity.image,
						entity.x,
						entity.y,
						0, 2.0, 2.0)
			elseif entity.name == "bullet" then
				love.graphics.draw(entity.image,
					entity.x, entity.y, entity.angle,
					1, 1, entity.offsetX, entity.offsetY)


			else
				love.graphics.draw(entity.image,
					entity.x, entity.y)
			end
		else -- out of range
			love.graphics.setColor(96,96,96,255)
			if entity.type == "floor" and data.player.local_map.name == "town" then
				love.graphics.drawq(env_sheet_img, entity.image,
						entity.x,entity.y,0,2.0,2.0)
			elseif entity.type == "wall" and entity.name == "tree" then

				love.graphics.draw(brown_grain_img,
					entity.x, entity.y)
				love.graphics.draw(entity.image,
					entity.x, entity.y)

			elseif entity.type == "floor" and entity.name == "tree" then
				love.graphics.draw(brown_grain_img,
				entity.x, entity.y)
				love.graphics.draw(tree_stump_img,
				entity.x, entity.y)

			elseif entity.type == "meta" then

				if entity.image ~= nil then

					love.graphics.draw(entity.image,
						entity.x, entity.y, 0, 16/entity.image:getWidth(),
						16/entity.image:getHeight())

					love.graphics.draw(bgb_outl_img,
						entity.x, entity.y)

				else
					love.graphics.setColor(0,0,0)
					love.graphics.rectangle("fill",entity.x,
						entity.y, tile_size, tile_size)
					love.graphics.setColor(96, 96, 96)
					love.graphics.draw(bgb_outl_img,
						entity.x, entity.y)

				end
			elseif entity.name == "stairs_up" then
				love.graphics.drawq(env_sheet_img,
						entity.image,
						entity.x,
						entity.y,
						0, 2.0, 2.0)

			elseif entity.name == "stairs_down" then
				love.graphics.drawq(env_sheet_img,
						entity.image,
						entity.x,
						entity.y,
						0, 2.0, 2.0)

			elseif entity.name == "bullet" then
				love.graphics.draw(entity.image,
					entity.x, entity.y, entity.angle,
					1, 1, entity.offsetX, entity.offsetY)

			else
				love.graphics.draw(entity.image,
					entity.x, entity.y)
			end
			love.graphics.setColor(255,255,255,255)
		end
	end

end

function draw_drop()

	if data.player.drop_mode == true then
		printc("Select (1-9) or enter (`) an item to drop")
	end

end

function draw_buy()
	if data.player.buy_mode == true then
		love.graphics.draw(trade_win, 2*tile_size, 2*tile_size)
	end
end

function draw_equip_hand()
	if data.player.equip_mode == "right" then
		printc("Select (1-9) or enter(`) a right-hand item")
	elseif data.player.equip_mode == "left" then
		printc("Select (1-9) or enter(`) a left-hand item")
	end

end

function trade_window(canvas, inventory, price_mod)
	canX = (grid_size-4)*tile_size
	canY = (grid_size-4)*tile_size
	love.graphics.setCanvas(canvas)
	love.graphics.setColor(62, 65, 77, 255)
	love.graphics.rectangle('fill',0,0,canX,canY)
	print("trade price mode:", price_mod)
	love.graphics.setColor(0,0,0,255)

	local pp = price_mod


	for i = 1, #inventory do
		if inventory[i] ~= nil then
			--print("inv value = ", inventory[i].value)
			local price = inventory[i].value*pp
			love.graphics.print("name",
				4*tile_size, 2*tile_size)
			love.graphics.print(inventory[i].name,
				4*tile_size, 2*tile_size+(i*tile_size))
			love.graphics.print("value",
				4*tile_size+128+64, 2*tile_size)
			love.graphics.print(price,
					4*tile_size+128+64, 2*tile_size+(i*tile_size))

			love.graphics.print("order no.",
				4*tile_size+128+128, 2*tile_size)
			love.graphics.print(i,
				4*tile_size+128+128, 2*tile_size+(i*tile_size))
		end
	end


	love.graphics.setCanvas()
	love.graphics.setColor(255,255,255,255)
	data.player.buy_mode = true
	print(table.tostring(inventory))
	print(#inventory)

end

function parse_con(text)
	print("parsing_con", text)

	local ns = local_map.name:sub(1,7)

	if data.player.buy_mode == true then

		int_text = 0 + text
		if maps.town.npcs[data.player.merchant_id].inventory[int_text] ~= nil then
			buy_item(int_text)
		end
		if #maps.town.npcs[data.player.merchant_id].inventory == 0 then
			data.player.buy_mode = false
		end
	elseif data.player.equip_mode == "right" then
		int_text = 0 + text
		p_equip_item("right",int_text)
	elseif data.player.equip_mode == "left" then
		int_text = 0 + text
		p_equip_item("left", int_text)
	elseif data.player.drop_mode == true then
		int_text = 0 + text
		p_drop_item(int_text)
		data.player.drop_mode = false

	elseif ns == "harvest" then
		-- CHEATS disable for release
		if text == "fog" then

			remove_fog(local_map.tiles)

		elseif text == "ph" then

			data.player.max_health = 9999
			data.player.health = 9999

		end

	end

	if text == "noun" then

		print(random_word("noun"))

	elseif text == "verb" then

		print(random_word("verb"))

	elseif text == "adv" then

		print(random_word("adv"))

	elseif text == "adj" then

		print(random_word("adj"))

	elseif text == "rsg" then

		if show_nar_image == false then
			this_thread = {}
			function this_thread.getName() return "rsg" end
			g_nar_image = adj_noun_string(local_map.meta_tiles)
			print("g_nar wid", g_nar_image:getWidth())
			print("g_nar height", g_nar_image:getHeight())
			print("g_nar type", g_nar_image:type())
			show_nar_image = true
		else
			show_nar_image = false
		end

	elseif text == "dbg_gis" then

		dbg_gis_img = true

	end

end
